package org.ans.jpodcast.client;

import java.util.ArrayList;

/**
 * This class contains the information about an established connection with Podcast Producer.
 * It is populated by calling the info REST service on the server.
 * Note that PCP1.0 (10.5) displays very little information, whereas PCP2.0 (10.6) displays much more.
 * Getters for properties that are not exposed on a PCP1.0 server will return null.
 * @author andy
 */
public class PcPProperties {

    private Float serverVersion;
    private boolean supportsBasicAuth;
    private boolean supportsDigestAuth;
    private boolean supportsKerberosAuth;
    private ArrayList<String> krbServicePrincipals;
    private String serverUUID;

    /**
     * @return the Podcast Producer server version (1.0 for Mac OS X Server 10.5.x, 2.0 for Mac OS X Server 10.6.x)
     */
    public Float getServerVersion() {
        return serverVersion;
    }

    public void setServerVersion(Float serverVersion) {
        this.serverVersion = serverVersion;
    }

    /**
     * @return true if HTTP Basic auth is supported, false otherwise
     */
    public boolean isSupportsBasicAuth() {
        return supportsBasicAuth;
    }

    public void setSupportsBasicAuth(boolean supportsBasicAuth) {
        this.supportsBasicAuth = supportsBasicAuth;
    }

    /**
     * @return true if the server supports HTTP Digest authentication, false otherwise
     */
    public boolean isSupportsDigestAuth() {
        return supportsDigestAuth;
    }

    public void setSupportsDigestAuth(boolean supportsDigestAuth) {
        this.supportsDigestAuth = supportsDigestAuth;
    }

    /**
     * @return true if the server supports Kerberos authentication, false otherwise.
     */
    public boolean isSupportsKerberosAuth() {
        return supportsKerberosAuth;
    }

    public void setSupportsKerberosAuth(boolean supportsKerberosAuth) {
        this.supportsKerberosAuth = supportsKerberosAuth;
    }

    /**
     * @return the Kerberos service principal for the Podcat Producer service
     */
    public ArrayList<String> getKrbServicePrincipals() {
        return krbServicePrincipals;
    }

    public void setKrbServicePrincipals(ArrayList<String> krbServicePrincipals) {
        this.krbServicePrincipals = krbServicePrincipals;
    }

    /**
     * @return the server's UUID
     */
    public String getServerUUID() {
        return serverUUID;
    }

    public void setServerUUID(String serverUUID) {
        this.serverUUID = serverUUID;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Podcast Producer server properties\n");
        sb.append("Server version: " + serverVersion + "\n");
        sb.append("Server UUID: " + serverUUID + "\n");
        sb.append("Basic auth supported: " + supportsBasicAuth + "\n");
        sb.append("Digest auth supported: " + supportsDigestAuth + "\n");
        sb.append("Kerberos auth supported: " + supportsKerberosAuth + "\n");
        if (krbServicePrincipals != null) {
            sb.append("Kerberos principals: ");
            for (String principal : krbServicePrincipals) {
                sb.append(principal + " ");
            }
            sb.append("\n");
        }
        return sb.toString();
    }

}
